﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;

namespace WindowsFormsApplication1.WebTest.WebTestXmlNodes
{
    [XmlRoot("RuleParameters", Namespace = XmlNamespace)]
    public class RuleParametersNode : GenericWebTestNode, IXmlSerializable
    {
        #region IXmlSerializable Members

        public System.Xml.Schema.XmlSchema GetSchema()
        {
            return null;
        }

        public void ReadXml(XmlReader reader)
        {
            Notification.BeginOperation("Processing Rule Parameters Node", NodeOperationEventArgs.EventImportance.Detailed);

            //Read the attributes of the RuleParameter tag
            ReadXmlAttributes(reader);

            //Read the RuleParameters tag
            reader.MoveToContent();
            bool isEmptyElement = reader.IsEmptyElement;

            reader.Read();

            while (!isEmptyElement && reader.NodeType != XmlNodeType.EndElement)
            {
                reader.MoveToContent();

                NodeDescriptionProperties nodeProperties = new NodeDescriptionProperties(this)
                                                               {
                                                                   Name = reader["Name"],
                                                                   Value = reader["Value"],
                                                                   Category = "Rule Parameters",
                                                                   WebTestNodeType = NodeDescriptionProperties.WebTestNodeTypes.Parameter
                                                               };


                //Read the Parameter
                //<RuleParameter Name="Required" Value="True" />
                _nodeProperties.Add(nodeProperties.Name, nodeProperties);

                //Read the empty tag <RuleParameter /> 
                reader.MoveToContent();
                reader.Read();
                reader.MoveToContent();

            }
            //Read the </RuleParameters> closing tag
            reader.MoveToContent();

            //If there is closing tag read it
            if (!isEmptyElement)
                reader.ReadEndElement();

            Notification.EndOperation();
        }


        #endregion

    }

}
